#include <iostream>
#include <string>

using namespace std;

//#define DEBUG

string S1; // 先序遍历字符串
string S2; // 中序遍历字符串

void PostorderrTtraversal(int left1, int right1, int left2, int right2) {
    if (left1 > right1 || left2 > right2)
        return;
    for (int i = left2; i <= right2; ++i) {
        if (S1[left1] == S2[i]) {
            PostorderrTtraversal(left1+1, left1+(i-left2), left2, i-1);
            PostorderrTtraversal(left1+(i-left2)+1, right1, i+1, right2);
            cout << S1[left1];
        }
    }
}

int
main() {
    while(cin >> S1 >> S2) {
#ifdef DEBUG
        cout << S1 << endl;
        cout << S2 << endl;
#endif
        PostorderrTtraversal(0, S1.length()-1, 0, S2.length()-1);
        cout << endl;

    }

	return 0;
}
